<!DOCTYPE html>
<html ng-app="dictApp" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <header th:replace="importCommon"></header>
    <link rel="stylesheet" th:href="@{/assets/jstree/themes/default/style.css}"/>
    <script th:src="@{/js/lib/angular/angular-sanitize.min.js}"></script>
    <script th:src="@{/js/common/customValid.js}"></script>
    <script th:src="@{/js/common/FormDirective.js}"></script>
    <script th:src="@{/js/system/controller/DictCtrl.js}"></script>
    <script th:src="@{/assets/jstree/jstree.min.js}"></script>
    <script th:src="@{/assets/jstree/checkboxTree.js}" type="text/javascript"></script>
    <title>字典管理</title>
    <style type="text/css">
        #menu-edit .add_menu tr {
            margin-bottom: 10px;
        }

        #menu-edit .add_menu td {
            line-height: 45px !important;
        }
    </style>
</head>
<body ng-controller="dictCtrl">
<div class="page-content" style="height:100%;padding:0;">
    <div id="treeMenu" style="width:20%;float: left;border-right: 2px solid #ccc;">
        <div style="height: 40px;line-height: 40px;">
            <div style="text-align: center;background: #0679CC;color: white;">
                字典管理
            </div>
            <div>
                <a href="javascript:void(0)" style="display: none;"></a>
                <a href="javascript:void(0)"></a>
            </div>
        </div>
        <div style="height: 463px;overflow:auto;">
            <div id="jstree"></div>
        </div>
    </div>
    <div id="content" style="width: 80%;float: right;height: 100%;overflow: auto;">
        <div class="Res commonManager">
            <div class="table_res_list">
                <table style="text-align: center;" id="Res_list" cellpadding="0" cellspacing="0"
                       class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>字典Code</th>
                        <th>字典值</th>
                        <th>是否目录</th>
                        <th>创建日期</th>
                        <th>最后更新日期</th>
                        <th>描述</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="dict in dictList">
                        <td class="atxt_name" ng-bind="dict.code"></td>
                        <td class="atxt_name" ng-bind="dict.name"></td>
                        <td class="atxt_name" ng-bind="dict.isCategory=='Y'? '是':'否'"></td>
                        <td ng-bind="dict.createAt | date:'yyyy-MM-dd HH:mm:ss'"></td>
                        <td ng-bind="dict.updateAt | date:'yyyy-MM-dd HH:mm:ss'"></td>
                        <td ng-bind="dict.description"></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <form name="form">
        <div id="Add_Dic_style" style="display: none">
            <div class="commonManager ">
                <div class="addCommon">
                    <ul class="clearfix">
                        <li ng-show="formTypeList.length">
                            <label class="label_name">父分类</label>
                            <select name="selectType" type="text" ng-model="dict.parentId"
                                    ng-options="(m.id) as m.name for m in formTypeList"
                                    ht-select-ajax="{url:'/dict/getCategory',field:'formTypeList'}"
                                    ht-validate="{required:true}" class="text_add">
                            </select>
                        </li>
                        <li>
                            <label class="label_name">字典Code</label>
                            <label>
                                <input name="name" ng-model="dict.code" type="text" value=""
                                       class="text_add" ht-validate="{required:true}"/>
                            </label>
                        </li>
                        <li>
                            <label class="label_name">字典名称</label>
                            <label>
                                <input name="name" ng-model="dict.name" type="text" value=""
                                       class="text_add" ht-validate="{required:true}"/>
                            </label>
                        </li>
                        <li>
                            <label class="label_name">是否分类</label>&#12288;&#12288;
                            <label>
                                <input name="isCategory" ng-model="dict.isCategory" type="radio" value="Y"
                                       class="text_add" ht-validate="{required:true}"/>是&#12288;&#12288;

                            </label>
                            <label>
                                <input name="isCategory" ng-model="dict.isCategory" type="radio" value="N"
                                       class="text_add" ht-validate="{required:true}"/>否
                            </label>
                        </li>
                    </ul>
                    <div class="Remark" style="padding-top: 20px;">
                        <label class="label_name">备注</label>
                        <label>
                                <textarea name="remark" ng-model="dict.description" cols="" rows=""
                                          style="width: 456px; height: 100px; padding: 5px;"></textarea>
                        </label>
                    </div>
                </div>
            </div>
            <div class="layui-layer-btn">
                <a class="layui-layer-btn0" ht-save="/dict/add" ng-model="dict">保存</a>
                <a class="layui-layer-btn1">取消</a>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    var layerIndex, jstree, currentNode;
    (function () {
        jstree = $('#jstree').jstree({
            "core": {
                "animation": 0,
                "check_callback": true,
                "themes": {"stripes": true},
                "data": {
                    "url": function (node) {
                        return _ctx + "/dict/getTree";
                    },
                    "data": function (node) {
                        return {"id": node.id};
                    },
                }
            },
            "types": {
                "#": {
                    "max_children": 1,
                    "valid_children": ["root"]
                },
                "root": {
                    "icon": "/static/3.3.3/assets/images/tree_icon.png",
                    "valid_children": ["default"]
                },
                "default": {
                    "valid_children": ["default", "file"]
                },
                "file": {
                    "icon": "glyphicon glyphicon-file",
                    "valid_children": []
                }
            },
            "plugins": ["contextmenu", "search", "types"],
            "contextmenu": {
                "items": {
                    "create": null,
                    "rename": null,
                    "remove": null,
                    "ccp": null,
                    "addDictType": {
                        "label": "&#12288;添&#12288;加&#12288;",
                        "_disabled": function (data) {
                            var selectData = getSelectItem(data);
                            return selectData.original.isCatagory == "N";
                        },
                        "action": function (data) {
                            openDictEdit("add", getSelectItem(data).id);
                        }
                    },
                    "editDictType": {
                        "label": "&#12288;编&#12288;辑&#12288;",
                        "_disabled": function (data) {
                            var selectData = getSelectItem(data);
                            return selectData.parent == "#";
                        },
                        "action": function (data) {
                            openDictEdit("edit", getSelectItem(data).id);
                        }
                    },
                    "delDictType": {
                        "separator_before": true,
                        "label": "&#12288;删&#12288;除&#12288;",
                        "_disabled": function (data) {
                            var selectData = getSelectItem(data);
                            return selectData.parent == "#";
                        },
                        "action": function (data) {
                            AngularUtil.triggerScopeFun("deleteById", getSelectItem(data).id);
                        }
                    }
                }
            }
        });
        function getSelectItem(data) {
            var inst = $.jstree.reference(data.reference),
                    obj = inst.get_node(data.reference);
            currentNode = obj;
            return obj;
        }

        $('#jstree').bind("activate_node.jstree", function (obj, e) {
            var menuId = e.node.id;
            if (menuId) {
                AngularUtil.triggerScopeFun("getParentByMenuId", menuId);
            }
        });
        $('#jstree').bind("show_contextmenu.jstree", function (obj, e) {
            // 如果是顶级菜单， 只允许添加分类
            if (e.node.parent == "#") {
                $(".vakata-contextmenu-disabled").hide();
            }
            if (e.node.original.isCatagory == "N") {
                $(".vakata-contextmenu-disabled").hide();
            }

        });
        function openDictEdit(action, id) {
            var scope = AngularUtil.getScope();

            if (action == "edit") {
                AngularUtil.triggerScopeFun("update", [0, id]);
            } else {
                scope.dict = {};
                scope.dict.parentId = Number(id);
                AngularUtil.triggerScopeFun("update", 1);
            }
            AngularUtil.setData(scope);
        }
    })();
</script>
</html>

